<template>
    <div>
        <TypeNav></TypeNav>
        <!-- 项目的最外层 -->
        <div class="outer">
            <!-- 窗口侧边栏 -->
            <div class="toolbar toolbar-wrap">
                <div class="content"></div>
                <div class="but list"></div>
                <div class="toolist">
                    <div class="pull">
                        <i class="tab-ico vip"></i>
                        <em class="tab-text">商品会员</em>
                    </div>
                    <div class="pull">
                        <i class="tab-ico cart"></i>
                        <em class="tab-text">购物车</em>
                    </div>
                    <div class="pull">
                        <i class="tab-ico follow"></i>
                        <em class="tab-text">我的关注</em>
                    </div>
                    <div class="pull">
                        <i class="tab-ico history"></i>
                        <em class="tab-text">我的足迹</em>
                    </div>
                    <div class="pull">
                        <i class="tab-ico message"></i>
                        <em class="tab-text">我的消息</em>
                    </div>
                    <div class="pull">
                        <i class="tab-ico jimi"></i>
                        <em class="tab-text">咨询</em>
                    </div>
                </div>
                <div class="back pull">
                    <i class="tab-ico top"></i>
                    <em class="tab-text">顶部</em>
                </div>
            </div>

            <!--list-content-->
            <div class="main">
                <div class="py-container">
                <SearchTag
                    :trademark="searchParams.trademark"
                    :searchProps="searchParams.props"
                    @deleteQueryTag="deleteQueryTag"
                    @deleteParamsTag="deleteParamsTag"
                    @deleteTradeMarkTag="deleteTradeMarkTag"
                    @deleteAttrTag="deleteAttrTag"
                ></SearchTag>
                <SearchSelector
                    @trademarkParams="trademarkParams"
                    @attrsParams="attrsParams"
                ></SearchSelector>
                    <SearchDetails
                        @searchListSort="searchListSort"
                        :PageNo="searchParams.pageNo"
                        :total="searchParams.total"
                        @changePageNo ="changePageNo"
                    ></SearchDetails>
                <SearchHot></SearchHot>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {mapActions} from "vuex";
import SearchTag from "@/pages/Search/components/SearchTag";
import SearchSelector from "@/pages/Search/components/SearchSelector";
import SearchDetails from "@/pages/Search/components/SearchDetails";
import SearchHot from "@/pages/Search/components/SearchHot";

export default {
    name: "Search",
    components: {SearchHot, SearchDetails, SearchSelector, SearchTag},
    data(){
        return{
            searchParams: {
                category1Id:"",
                category2Id:"",
                category3Id: "",
                categoryName: "",
                keyword: "",
                order: "",
                pageNo: 1,
                pageSize: 10,
                props: [],
                trademark: "",
                total:60,
            }
        }
    },
    beforeMount() {
        //初始化之前就要合并query和params参数
        this.ininParams()
    },
    mounted() {
        this.getSearchList(this.searchParams)
    },
    methods:{
        ...mapActions("search",["getSearchList"]),

        ininParams(){
            const {categoryName,category1Id="",category2Id="",category3Id=""} = this.$route.query

            const {searchKey=""} = this.$route.params


            this.searchParams = {
                ...this.searchParams,
                categoryName,
                category1Id,
                category2Id,
                category3Id,
                keyword: searchKey,
            }
        },

        trademarkParams(tm){
            // console.log(tm)
            this.searchParams.trademark = `${tm.tmId}:${tm.tmName}`

            this.getSearchList(this.searchParams)
        },

        attrsParams(attr){
            // console.log(attr)
            const {attrValue,attrId,attrName} = attr
            const str = `${attrId}:${attrValue}:${attrName}`
            if(this.searchParams.props.includes(str)) return
            this.searchParams.props.push(str)

            this.getSearchList(this.searchParams)
        },
        deleteQueryTag(){
            this.searchParams = {
                ...this.searchParams,
                category1Id:"",
                category2Id:"",
                category3Id: "",
                categoryName: "",
            }
            const params = this.$route.params
            this.$router.push({
                name:"search",
                params
            })
        },
        deleteParamsTag(){
            this.searchParams = {
                ...this.searchParams,
                keyword: ""
            };
            const query  = this.$route.query

            //通知组件清空
            this.$bus.$emit("notifyHeader")

            this.$router.push({
                name:"search",
                query
            })
        },
        deleteTradeMarkTag(){
            this.searchParams = {
                ...this.searchParams,
                trademark: ""
            }

            this.getSearchList(this.searchParams)
        },
        deleteAttrTag(tag){
            this.searchParams.props =  this.searchParams.props.filter(item=>tag != item)

            this.getSearchList(this.searchParams)
        },

        searchListSort(order){
            this.searchParams.order = order

            this.getSearchList(this.searchParams)
        },
        changePageNo(page){
            this.searchParams.pageNo = page

            this.getSearchList(this.searchParams)
        },

    },
    watch:{
        $route(){
            //修改数据
            this.ininParams()
            //发送请求
            this.getSearchList(this.searchParams)
        }
    }
}
</script>

<style scoped lang="less">
.outer{
    .toolbar{
        position: fixed;
        z-index: 999;
        width: 300px;
        height: 100%;
        background-color: #7a6e6e;
        transition: right .3s ease-in-out 0s;
        &.toolbar-out{
            top: 0px;
            right: 0px;
        }
        &.toolbar-wrap{
            top: 0px;
            right: -294px;
        }
        .content{
            position: relative;
            left: 6px;
            width: 294px;
            background-color: bisque;
            height: 100%;
            z-index: 99;
        }
        .but{
            position: relative;
            width: 35px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            margin-bottom: 1px;
            cursor: pointer;
            background-color: #7a6e6e;
            border-radius: 3px 0 0 3px;
            position: absolute;
            top: 0;
            /*right: -6px;*/
            left: -29px;
            &.list{
                background-image: url(./images/list.png);
                background-repeat: no-repeat;
                background-size: cover;
            }
            &.pull-wrap{
                background-image: url(./images/cross.png);
                background-repeat: no-repeat;
                background-size: cover;
            }
        }
        .toolist{
            position: absolute;
            top: 50%;
            left: -29px;
            width: 35px;
            margin-top: -80px;
            /*background-color: cadetblue;*/
            .pull{
                position: relative;
                width: 35px;
                height: 35px;
                line-height: 35px;
                text-align: center;
                margin-bottom: 1px;
                cursor: pointer;
                background-color: #7a6e6e;
                border-radius: 3px 0 0 3px;
                z-index: 66;
                .vip{
                    background-image: url(./images/toolbars.png);
                    background-position: -88px -175px;
                }
                .cart{
                    background-image: url(./images/toolbars.png);
                    background-position: -50px 0;
                }
                .follow{
                    background-image: url(./images/toolbars.png);
                    background-position: -50px -50px;
                }
                .history{
                    background-image: url(./images/toolbars.png);
                    background-position: -50px -100px;
                }
                .message{
                    background-image: url(./images/toolbars.png);
                    background-position: -190px -150px;
                }
                .jimi{
                    background-image: url(./images/toolbars.png);
                    background-position: -50px -150px;
                }
                .top{
                    background-image: url(./images/toolbars.png);
                    background-position: -50px -250px;
                }

                .tab-text {
                    width: 62px;
                    height: 35px;
                    line-height: 35px;
                    color: #fff;
                    text-align: center;
                    font-family: 微软雅黑;
                    position: absolute;
                    /*position: relative;*/
                    z-index: 1;
                    left: 35px;
                    top: 0;
                    background-color: #7a6e6e;
                    border-radius: 3px 0 0 3px;
                    font-style: normal;
                    -webkit-transition: left .3s ease-in-out .1s;
                    transition: left .3s ease-in-out .1s;
                }
                .tab-ico{
                    display: inline-block;
                    position: relative;
                    /*background-images: url(img/toolbars.png);*/
                    background-color:#7a6e6e ;
                    border-radius: 3px 0 0 3px;
                    z-index: 2;
                    width: 35px;
                    height: 35px;
                }
            }
        }

        &>.pull{
            position: relative;
            width: 35px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            margin-bottom: 1px;
            cursor: pointer;
            background-color: #7a6e6e;
            border-radius: 3px 0 0 3px;
            z-index: 66;
            .tab-ico{
                display: inline-block;
                position: relative;
                /*background-images: url(img/toolbars.png);*/
                background-color:#7a6e6e ;
                border-radius: 3px 0 0 3px;
                z-index: 2;
                width: 35px;
                height: 35px;
            }
            .top{
                background-image: url(./images/toolbars.png);
                background-position: -50px -250px;
            }

            .tab-text {
                width: 62px;
                height: 35px;
                line-height: 35px;
                color: #fff;
                text-align: center;
                font-family: 微软雅黑;
                position: absolute;
                /*position: relative;*/
                z-index: 1;
                left: 35px;
                top: 0;
                background-color: #7a6e6e;
                border-radius: 3px 0 0 3px;
                font-style: normal;
                -webkit-transition: left .3s ease-in-out .1s;
                transition: left .3s ease-in-out .1s;
            }
        }
        &>.back{
            position: absolute;
            bottom: 0;
            /*right: -6px;*/
            left: -29px;
            display: inline-block;
            background-image: url(./images/toolbars.png);

        }
    }
    .main{
        margin: 10px 0;
        .py-container{
            width: 1200px;
            margin: 0 auto;
        }
    }
}
</style>